import java.net.InetAddress;
import java.net.InetSocketAddress;


import rice.environment.Environment;

/**
 * class com o método main - cria uma instancia de FileSync que é
 * a classe principal da aplicação
 * 
 * @author alison
 *
 */
public class SyncPastry 
{
	public static void main(String[] args) throws Exception
	{
		System.out.println("GDD - Iniciando o programa");

		// Se não tiver parametro inicia lendo o diretório local
		String root = (args.length > 0 ? args[0]: ".");

		 // Loads pastry settings
	    Environment env = new Environment();

	    // disable the UPnP setting (in case you are testing this on a NATted LAN)
	    env.getParameters().setString("nat_search_policy","never");
	    
	    try {
	      // the port to use locally
	      int bindport = Integer.parseInt(args[1]);

	      // build the bootaddress from the command line args
	      InetAddress bootaddr = InetAddress.getByName(args[2]);
	      int bootport = Integer.parseInt(args[3]);
	      InetSocketAddress bootaddress = new InetSocketAddress(bootaddr,bootport);

	      // Cria uma instancia do FileSync
		FileSync fs = new FileSync(root, bindport, bootaddress, env);
	    } catch (Exception e) {
	      // remind user how to use
	      System.out.println("Usage:"); 
	      System.out.println("java -jar syncp2p.jar root_directory localbindport bootIP bootPort");
	      System.out.println("Example: java -jar syncp2p.jar 9001 192.168.1.1 9001");
	      throw e; 
	    }
	}
	
}
